import { createApp } from 'vue'
import pinia from '@/stores'
import { userStore } from './stores'
import App from './App.vue'
import router from './router'

import persist from 'pinia-plugin-persistedstate'
const app = createApp(App)
app.use(pinia.use(persist))
app.use(router)

app.mount('#app')
//全局导航守卫
const userstore = userStore()
router.beforeEach((to, from, next) => {
  if (to.path == '/user/login') {
    next()
  } else {
    if (userstore.getToken() === '') {
      next({ path: '/user/login' })
    }

    next()
  }
})
